﻿<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Oracle 11g RAC安装运维总结</title>
  <link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>

<body class="stackedit">
  <div class="stackedit__html"><p></p><div class="toc"><h3>Oracle 11g RAC运维总结</h3><ul><li><a href="#1__1">1 术语解释</a></li><ul><li><a href="#11_HA_2">1.1 高可用（HA）</a></li><li><a href="#12_LB_4">1.2 负载均衡（LB）</a></li><li><a href="#13_RAC_6">1.3 RAC集群</a></li><li><a href="#14_CRS_8">1.4 CRS</a></li></ul><li><a href="#2__11">2 架构</a></li><ul><li><a href="#21_RAC_12">2.1 RAC环境组成</a></li><ul><li><a href="#211__13">2.1.1 硬件环境</a></li><li><a href="#212__22">2.1.2 软件组成</a></li></ul><li><a href="#22_CRS_36">2.2 CRS组成</a></li><li><a href="#23_RAC_85">2.3 单实例与RAC环境</a></li></ul><li><a href="#3Oracle_11g_RAC_106">3.Oracle 11g RAC集群搭建</a></li><ul><li><a href="#31__107">3.1. 配置网络</a></li><ul><li><a href="#311_108">3.1.1网络划分</a></li><li><a href="#312__123">3.1.2 划分用户和组</a></li><li><a href="#313__133">3.1.3 目录划分</a></li></ul><li><a href="#32__147">3.2 创建组和用户</a></li><ul><li><a href="#321__150">3.2.1 创建组，根据前面的组划分创建</a></li><li><a href="#322_159">3.2.2创建用户</a></li><li><a href="#323_164">3.2.3更改用户密码</a></li><li><a href="#324_172">3.2.4创建软件安装目录</a></li><li><a href="#325_196">3.2.5设置用户的环境变量</a></li></ul><li><a href="#33__242">3.3 配置内核参数</a></li><li><a href="#34__309">3.4 时间同步</a></li></ul><li><a href="#4__371">4 维护</a></li><ul><li><a href="#41__372">4.1 集群维护</a></li><ul><li><a href="#411_CRS_374">4.1.1 启动和停止CRS</a></li><li><a href="#412_CRS_394">4.1.2 验证CRS</a></li><li><a href="#413_CRS_431">4.1.3 禁用与启用CRS</a></li><li><a href="#414__439">4.1.4 显示集群资源状态</a></li><li><a href="#415_oifcfg_448">4.1.5 使用oifcfg配置集群网络</a></li></ul><li><a href="#42_OCR_461">4.2 管理OCR</a></li><ul><li><a href="#421__464">4.2.1 备份</a></li><li><a href="#422__502">4.2.2 恢复</a></li><li><a href="#423__522">4.2.3 镜像维护</a></li><li><a href="#424_OCR_536">4.2.4 移动OCR</a></li><li><a href="#425_OLR_545">4.2.5 管理OLR</a></li></ul><li><a href="#43_Voting_Disk_552">4.3 管理Voting Disk</a></li><li><a href="#44_ASM_568">4.4 ASM维护</a></li><ul><li><a href="#441_ASM_572">4.4.1 ASM实例创建</a></li><li><a href="#442__577">4.4.2 磁盘组的创建与删除</a></li><li><a href="#443__605">4.4.3 磁盘组的挂载与卸载</a></li><li><a href="#444__624">4.4.4 磁盘的添加与删除</a></li><li><a href="#445__647">4.4.5 磁盘组信息的查询</a></li><li><a href="#446__651">4.4.6 磁盘组的重平衡</a></li><li><a href="#447_ASM_656">4.4.7 ASM工具</a></li></ul><li><a href="#45__663">4.5 数据库维护</a></li><ul><li><a href="#451__664">4.5.1 参数维护</a></li><li><a href="#452__682">4.5.2 启动和停止实例</a></li><li><a href="#453_UNDO_695">4.5.3 管理UNDO</a></li><li><a href="#454_redo_log_707">4.5.4 管理redo log</a></li><li><a href="#455__710">4.5.5 在线日志</a></li><li><a href="#456__725">4.5.6 归档日志</a></li><li><a href="#457__744">4.5.7 管理服务</a></li><li><a href="#458__759">4.5.8 备份与恢复</a></li><li><a href="#459__773">4.5.9 查看监听</a></li></ul><li><a href="#46__785">4.6 告警日志查看</a></li></ul></ul></div><p></p>
<h1><a id="1__1"></a>1 术语解释</h1>
<h2><a id="11_HA_2"></a>1.1 高可用（HA）</h2>
<p>什么是高可用？顾名思义我们能轻松地理解是高度可用的意思，也说是说高可用（high availability）指的是运行时间能满足预计或期望的一个系统或组件，我们常听说的247365系统，这种系统追求一种不间断提供服务的目标，任何时候都不能停止服务，否则会给用户造成比较大的影响。在信息、通讯、互联网技术发展如此快的今天，越来越多的系统都希望成为一个高可用的系统，比如银行、证券系统等。</p>
<h2><a id="12_LB_4"></a>1.2 负载均衡（LB）</h2>
<p>负载均衡（load balance）是指将业务的负载尽可能平均、合理地分摊到集群的各个节点，每个节点都可以处理一部分负载，并且可以根据节点负载进行动态平衡，提高各个节点硬件资源的利用率以及降低单节点因为负载过高而导致的故障。</p>
<h2><a id="13_RAC_6"></a>1.3 RAC集群</h2>
<p>RAC集群，全称Real Application Clusters，译为“实时应用集群”，是Oracle提供的一种高可用、并行集群系统，RAC除了具有高可用能力还有负载均衡能力，整个RAC集群系统由Oracle Clusterware （集群软件）和 Real Application Clusters（RAC)两大部分组成。 我们平时一直经常提的RAC，它仅仅是RAC集群中的一部分，是运行在集群软件Oracle Clusterware上的一个应用，就是数据库，它和集群软件的关系类似单机环境中应用程序和操作系统的关系。</p>
<h2><a id="14_CRS_8"></a>1.4 CRS</h2>
<p>我们知道RAC集群需要集群软件，那么CRS是什么呢？在Oracle 10g版本前，RAC集群所需的集群软件依赖于硬件厂商，在不同平台上实施RAC集群都需要安装和配置厂商的集群软件，而Oracle只提供了Linux和Windows平台上的集群软件，叫Oracle Cluster Manager。但从10.1版本开始，Oracle推出了一个与平台独立的集群产品：Cluster Ready Service，简称CRS，从此RAC集群的实施不再依赖各个硬件厂商，从10.2版本开始，Oracle将这个集群产品改名为Oracle Clusterware，在11g中又被称为GI（Oracle Grid Infrastructure），但我们叫惯了CRS，所以平时很多时候也就称之为CRS，这个产品并不局限用于数据库的集群，其他应用都可以借用其API轻易实现集群功能。</p>
<h1><a id="2__11"></a>2 架构</h1>
<h2><a id="21_RAC_12"></a>2.1 RAC环境组成</h2>
<h3><a id="211__13"></a>2.1.1 硬件环境</h3>
<p>整个RAC集群的硬件环境包括主机、共享存储、互联网络设备。</p>
<ul>
<li>1.主机（节点）<br>
一个RAC集群环境中至少有两台主机，也就是两个节点，每个节点的硬件配置应该都一样，每个节点至少配置两块物理网卡。</li>
<li>2.共享存储<br>
在RAC集群中，最重要的是共享存储，RAC是一个“多实例、单一数据库”的架构，所有的节点共享一个数据库。数据文件、联机日志、参数文件、控制文件都必须放在共享存储上以保证每个节点的实例都能访问。每个节点必须安装HBA卡，然后通过光纤线和存储设备连接。</li>
<li>3.互联网络设备
<ul>
<li>1） 两块网卡：也就是上面所说的每个节点上必须至少配置两块物理网卡。一块网卡用于集群内部的私有通信，集群节点间数据块的传输都是通过这块网卡，我们称之为私有网卡，上面配的IP称为Private IP；另一块网卡用于对外服务，比如数据库的查询等，我们称之为公有网卡，上面配的IP称为Public IP。除此之外，每个节点还有第三个IP，我们称之为VIP（Virtual IP）,在所有节点都正常运行时，每个节点的VIP会被分配到公有网卡上，当某个节点出现故障宕机时，这个节点的VIP会被移到还在正常运行节点的公有网卡上。</li>
<li>2） 网络交换机：整个RAC集群中需要几个网络交换机呢？个人认为至少两个。一个用于连接所有节点的公有网卡以提供对外的数据库服务，一个用于连接各个节点之间的私有网卡（当然Oracle官方也认为如果是两个节点，其实也可以通过网线直连的方式，但是生产环境中几乎不存在这种方式）以传递集群节点之间的心跳数据和数据库数据块（Cache Fusion）。</li>
</ul>
</li>
</ul>
<h3><a id="212__22"></a>2.1.2 软件组成</h3>
<p>概括来说，RAC集群的软件组成包含：操作系统、集群软件、集群文件系统、数据库软件。</p>
<ul>
<li>1.操作系统<br>
每个节点上所安装的操作系统必须是相同版本的，操作系统在RAC架构中所处位置是硬件与集群件中间。</li>
<li>2.集群件（CRS）<br>
集群件是安装在操作系统之上的一个特殊软件，负责管理整个集群环境中的硬件资源，并为上层的RAC集群提供基础服务。它与上层应用（例如数据库）的关系类似于单机环境中操作系统和应用程序的关系。单机环境下，OS能代理应用程序对硬件访问，但是在集群中有多台计算机，把整个集群想象成一台虚拟的计算机，那集群件就是这台虚拟计算机上的操作系统，RAC是运行在它上面的一个应用程序。</li>
<li>3.集群文件系统<br>
RAC集群中有很多的文件必须放在共享存储上，保证所有节点都能访问。这就需要对节点的访问进行控制，普通的文件系统并不支持集群功能，必须采取特殊的存储策略。在10g以前，Oracle只提供了对裸设备的支持，并没有提供集群文件系统，但从Oracle 10g开始，Oracle提供了OCFS和ASM两种集群文件系统，后者在现在的环境中用的最多，也最为流行。</li>
<li>4.数据库软件<br>
这个就是rdbms软件了，只有安装了数据库软件，我们才能创建数据库，存储数据，对外提供数据服务。</li>
</ul>
<p>这里附上一张RAC集群简单的拓扑图：</p>
<p><img src="https://img-blog.csdnimg.cn/703da863799c48b884fb7adc63a5db62.png" alt="在这里插入图片描述"></p>
<h2><a id="22_CRS_36"></a>2.2 CRS组成</h2>
<p>Oracle Clusterware，在11g中又被称为GI（Oracle Grid Infrastructure），我们这里统一直接称之为CRS好了，它由磁盘文件、后台进程、网络组件组成。</p>
<ul>
<li>1.磁盘文件<br>
OCR：OCR（Oracle Cluster Registry）是为了避免每个节点的配置信息不同步而保存了整个集群的配置信息，且整个集群只有一份配置，所有节点共享，配置信息以“Key-value”的形式保存其中。当集群配置需要发生改变时，每个节点都有一个OCR Process来读取OCR Cache中的内容，而只有一个节点（OCR Master）有权限读写OCR Disk的内容，然后同步到本地和其他节点的OCR Cache。<br>
Voting Disk：Voting Disk这个文件主要用于记录各个节点的状态，以防在某个或某几个节点出现问题时，决定哪部分节点具有集群的控制权，而把其他节点从集群中剔除，从而能够继续正常地对外提供服务。</li>
<li>2.CRS后台进程<br>
其中最重要的三个进程是CRSD、CSSD、EVMD，分别对应了CRS、CSS、EVM三个服务，而每个服务又是由一系列的模块组成的，我们可以通过crsctl命令来查看有哪些模块组成，如查看css服务，crsctl lsmodules css。那么这三个进程又是什么时候启来的呢？在安装Clusterware的最后阶段，会要求在每个节点中执行root.sh脚本，这个脚本会在/etc/inittab文件中最后三行添加三个后台进程的启动信息，类似：</li>
</ul>
<pre><code>h1:35:respawn:/etc/init.d/init.evmd run &gt;/dev/null 2&gt;&amp;1 &lt;/dev/null
h2:35:respawn:/etc/init.d/init.cssd run &gt;/dev/null 2&gt;&amp;1 &lt;/dev/null
h3:35:respawn:/etc/init.d/init.crsd run &gt;/dev/null 2&gt;&amp;1 &lt;/dev/null
</code></pre>
<p>如果CRSD和EVMD出现异常，系统会自动重启这两个进程。但是如果CSSD进程异常，系统会立即重启。罗列Linux和Unix中各个服务所对应的进程如下：<br>
<img src="https://img-blog.csdnimg.cn/dba265270bf140d1985db2e815de66dc.png" alt="在这里插入图片描述"><br>
以Oracle 11g在linux上为例来查看一下各个进程：</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>oracle@node1 <span class="token operator">~</span><span class="token punctuation">]</span>$ ps <span class="token operator">-</span>ef<span class="token operator">|</span>grep css
root      <span class="token number">4408</span>     <span class="token number">1</span>  <span class="token number">0</span> <span class="token number">04</span><span class="token operator">:</span><span class="token number">23</span> <span class="token operator">?</span>        <span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span><span class="token operator">:</span><span class="token number">05</span> <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>cssdmonitor
root      <span class="token number">4427</span>     <span class="token number">1</span>  <span class="token number">0</span> <span class="token number">04</span><span class="token operator">:</span><span class="token number">23</span> <span class="token operator">?</span>        <span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span><span class="token operator">:</span><span class="token number">05</span> <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>cssdagent
grid      <span class="token number">4445</span>     <span class="token number">1</span>  <span class="token number">0</span> <span class="token number">04</span><span class="token operator">:</span><span class="token number">23</span> <span class="token operator">?</span>        <span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span><span class="token operator">:</span><span class="token number">56</span> <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>ocssd<span class="token punctuation">.</span>bin
<span class="token punctuation">[</span>grid@node1 bin<span class="token punctuation">]</span>$ ps <span class="token operator">-</span>ef<span class="token operator">|</span>grep crs
root      <span class="token number">4767</span>     <span class="token number">1</span>  <span class="token number">0</span> <span class="token number">04</span><span class="token operator">:</span><span class="token number">24</span> <span class="token operator">?</span>        <span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span><span class="token operator">:</span><span class="token number">20</span> <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>crsd<span class="token punctuation">.</span>bin reboot

<span class="token punctuation">[</span>grid@node1 bin<span class="token punctuation">]</span>$ ps <span class="token operator">-</span>ef<span class="token operator">|</span>grep evm
grid      <span class="token number">4623</span>     <span class="token number">1</span>  <span class="token number">0</span> <span class="token number">04</span><span class="token operator">:</span><span class="token number">24</span> <span class="token operator">?</span>        <span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span><span class="token operator">:</span><span class="token number">07</span> <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>evmd<span class="token punctuation">.</span>bin
grid      <span class="token number">4861</span>  <span class="token number">4623</span>  <span class="token number">0</span> <span class="token number">04</span><span class="token operator">:</span><span class="token number">24</span> <span class="token operator">?</span>        <span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span><span class="token operator">:</span><span class="token number">00</span> <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>evmlogger<span class="token punctuation">.</span>bin <span class="token operator">-</span>o <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>evm<span class="token operator">/</span>log<span class="token operator">/</span>evmlogger<span class="token punctuation">.</span>info <span class="token operator">-</span>l <span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>evm<span class="token operator">/</span>log<span class="token operator">/</span>evmlogger<span class="token punctuation">.</span>log

</code></pre>
<ul>
<li>我们来看一下各个进程的作用：
<ul>
<li>OCSSD<br>
进程是Clusterware最关键的进程，如果出现异常会导致系统重启，这个进程提供CSS（Cluster Synchronization Service）服务，它通过多种心跳机制实时监控集群的健康状态，提供集群的基础服务功能。</li>
<li>CRSD<br>
是实现高可用的主要进程，它提供了CRS（Cluster Ready Service）服务。这些服务包括Clusterware上集群资源的关闭、重启、转移、监控等。集群资源分为两类：一类是Nodeapps型的，就是说每个节点只需要一个就行，这类有GSD(Global Service Daemon)、ONS（Oracle Notification Service Daemon）、VIP、Listener；另一类是Database-Related，就是和数据库相关，不受节点限制，这类有Database、Instance、Service等。</li>
<li>EVMD<br>
该进程负责发布CRS产生的各种事件，同时也是CRSD和CSSD两个进程之间的桥梁。</li>
<li>RACGIMON<br>
该进程负责检查数据库健康状态，负责Service的启动、停止、故障转移等。</li>
<li>OPROCD<br>
在非Linux平台，且没有使用第三方集群软件时才有该进程，用来检测节点的CPU挂起，起过1.5秒会重启节点。</li>
<li>OHASd<br>
Oracle在11gR2引入了OHASd（Oracle High Availability Services Daemon，Oracle高可用服务后台进程），再由它来启动其他的集群件守护进程。</li>
</ul>
</li>
<li>3.网络组件<br>
我们从RAC集群架构中的硬件环境组成已经知道，集群环境中的节点上必须配置两块物理网卡，在公网网卡上面我们除了设置公有IP外还设置了VIP，Oracle的TAF（所谓TAF就是连接建立后，如果某个实例发生故障，连接到这个实例上的用户会被自动迁移到其他健康实例上，对于应用程序而言，这个迁移过程透明，不需要人工介入）是建立在VIP技术上的，它与IP最主要的不同就是VIP是浮动的，IP是固定的，当某个节点宕机时，该节点上的VIP自动会移到健康节点的公网网卡上，所能对该节点的连接自动会移到健康节点。<br>
VIP还有几个特点需要我们注意一下：
<ul>
<li>a) VIP是在Clusterware安装最后阶段通过脚本vipca创建的；</li>
<li>b) VIP作为一个Nodeapps类型的CRS资源注册到OCR，并由CRS维护状态；</li>
<li>c) 每个节点的监听会同时在Public网卡的Public Ip和VIP两个地址上监听；</li>
<li>d) 客户端的tnsnames.ora一般配置指向节点的VIP</li>
</ul>
</li>
</ul>
<h2><a id="23_RAC_85"></a>2.3 单实例与RAC环境</h2>
<ul>
<li>1、 单实例与RAC环境对比<br>
<img src="https://img-blog.csdnimg.cn/bf62bd5539154386add7e3d31fa320d9.png" alt="在这里插入图片描述"></li>
<li>2、 RAC新增的组件和后台进程<br>
RAC的环境中虽然每个实例都有自己的buffer cache与shared pool，但它们现在已经变成全局的，需要特殊处理才能做到没有冲突、无损坏地管理资源，所以也新增了一些单实例环境中没有的组件，最主要的有以下两部分：
<ul>
<li>GRD<br>
RAC实例的SGA中多了一个GRD（Global Resource Directory）部分，Oracle数据库中数据的操作都是在内存SGA中完成的，与传统的单实例数据库不同，RAC有多个实例，每个数据块在任何一个实例中都有拷贝，RAC必须知道这些拷贝的分布、版本、状态，而GRD就是保存这种信息的内存区。值得注意的是，每个节点都只有部分GRD内容，所有节点合在一起才能构成完整的GRD。</li>
<li>后台进程<br>
RAC也有和单实例中的DBWR、LGWR、ARCn、CKPT这些后台进程，此外还有一些RAC特有的后台进程：<br>
<strong>lms</strong><br>
该进程是Cache Fusion的主要进程，负责数据块在实例间的传递，对应的服务是GCS（Global Cache Service），可以通过GCS_SERVER_PROCESSES参数来控制进程的数量，默认是2个，取值范围为0~9。<br>
<strong>lmd</strong><br>
该进程提供GES（Global Enqueue Service）服务，在多个实例间协调对数据块的访问序，保证数据的一致性访问，和LMSn进程以及GRD共同构成RAC的核心功能Cache Fusion。<br>
<strong>lck</strong><br>
这个进程负责Non-Cache Fusion资源的同步访问，每个实例都有一个LCK进程。<br>
<strong>lmon</strong><br>
各个实例的LMON进程都会定期通信，检查集群中各节点的健康状态，当某个节点出现故障，该进程负责集群重构、GRD恢复等，它提供的服务是CGS（Cluster Group Services）。<br>
<strong>diag</strong><br>
Diag进程监控实例的健康状态，并在实例出现运行错误时收集诊断数据记录到Alert.log日志中。<br>
<strong>GSD</strong><br>
这个进程负责从客户端工具，比如srvctl接收用户命令，为用户提供管理接口。</li>
</ul>
</li>
</ul>
<h1><a id="3Oracle_11g_RAC_106"></a>3.Oracle 11g RAC集群搭建</h1>
<h2><a id="31__107"></a>3.1. 配置网络</h2>
<h3><a id="311_108"></a>3.1.1网络划分</h3>

<table>
<thead>
<tr>
<th>Interface</th>
<th>RAC1</th>
<th>RAC2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Public IP</td>
<td>192.168.88.100</td>
<td>192.168.88.101</td>
</tr>
<tr>
<td>Private IP</td>
<td>192.168.137.128</td>
<td>192.168.137.129</td>
</tr>
<tr>
<td>VIP</td>
<td>192.168.88.213</td>
<td>192.168.88.214</td>
</tr>
<tr>
<td>SCAN</td>
<td>192.168.88.200</td>
<td>192.168.88.200</td>
</tr>
</tbody>
</table><p><img src="https://img-blog.csdnimg.cn/ec6b4baa9182454b8417c33c7727b79a.png" alt="在这里插入图片描述"><br>
此时可以由192.168.137.128远程ssh到192.168.88.100，表示两块网卡都能用<br>
<img src="https://img-blog.csdnimg.cn/0115272f81df4d8b82a33cfb6c3e4cbb.png" alt="在这里插入图片描述"><br>
进入rac1的/etc/hosts文件，做以下配置<br>
<img src="https://img-blog.csdnimg.cn/f8e5a01f0e6a4c758c4e981bed39f748.png" alt="在这里插入图片描述"></p>
<p>此时在终端ping rac1，结果如下所示，这表示我们上一步的修改已经生效了<br>
<img src="https://img-blog.csdnimg.cn/bd858c9cdaf4411b9dc8c087fcd857b0.png" alt="在这里插入图片描述"></p>
<h3><a id="312__123"></a>3.1.2 划分用户和组</h3>

<table>
<thead>
<tr>
<th>Group</th>
<th>grid</th>
<th>oracle</th>
</tr>
</thead>
<tbody>
<tr>
<td>oinstall</td>
<td>✔</td>
<td>✔</td>
</tr>
<tr>
<td>dba</td>
<td>✔</td>
<td>✔</td>
</tr>
<tr>
<td>oper</td>
<td></td>
<td>✔</td>
</tr>
<tr>
<td>asmadmin</td>
<td>✔</td>
<td></td>
</tr>
<tr>
<td>asmdba</td>
<td>✔</td>
<td>✔</td>
</tr>
<tr>
<td>asmoper</td>
<td>✔</td>
<td></td>
</tr>
</tbody>
</table><p>分别用grid用户和oracle用户管理集群软件和关系型数据库软件.</p>
<h3><a id="313__133"></a>3.1.3 目录划分</h3>
<pre><code class="prism language-javascript">Grid Infrastructure

<span class="token keyword">export</span> <span class="token constant">HOME</span><span class="token operator">=</span><span class="token operator">/</span>home<span class="token operator">/</span>grid
<span class="token keyword">export</span> <span class="token constant">ORACLE_BASE</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>gridbase
<span class="token keyword">export</span> <span class="token constant">ORACLE_HOME</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>grid

Oracle Database

<span class="token keyword">export</span> <span class="token constant">HOME</span><span class="token operator">=</span><span class="token operator">/</span>home<span class="token operator">/</span>oracle
<span class="token keyword">export</span> <span class="token constant">ORACLE_BASE</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>oracle
<span class="token keyword">export</span> <span class="token constant">ORACLE_HOME</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>oracle<span class="token operator">/</span>db
</code></pre>
<h2><a id="32__147"></a>3.2 创建组和用户</h2>
<h3><a id="321__150"></a>3.2.1 创建组，根据前面的组划分创建</h3>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># groupadd oinstall
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># groupadd dba
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># groupadd oper
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># groupadd asmadmin
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># groupadd asmdba
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># groupadd asmoper
</code></pre>
<h3><a id="322_159"></a>3.2.2创建用户</h3>
<pre><code class="prism language-javascript">useradd <span class="token operator">-</span>g oinstall <span class="token operator">-</span><span class="token constant">G</span> dba<span class="token punctuation">,</span>asmadmin<span class="token punctuation">,</span>asmdba<span class="token punctuation">,</span>asmoper grid
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># useradd <span class="token operator">-</span>g oinstall <span class="token operator">-</span><span class="token constant">G</span> dba<span class="token punctuation">,</span>oper<span class="token punctuation">,</span>asmdba oracle
</code></pre>
<h3><a id="323_164"></a>3.2.3更改用户密码</h3>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># passwd oracle
<span class="token punctuation">[</span>root@rac1 <span class="token operator">~</span><span class="token punctuation">]</span># passwd grid
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/3a3fabb1dfbd48398719b400481b5a3f.png" alt="在这里插入图片描述"><br>
切换用户，看看grid和oracle用户的家目录，如下所示<br>
<img src="https://img-blog.csdnimg.cn/7be240ca67c448d2b9f7665ef2a349f6.png" alt="在这里插入图片描述"></p>
<h3><a id="324_172"></a>3.2.4创建软件安装目录</h3>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 u01<span class="token punctuation">]</span># mkdir gridbase
<span class="token punctuation">[</span>root@rac1 u01<span class="token punctuation">]</span># mkdir grid
<span class="token punctuation">[</span>root@rac1 u01<span class="token punctuation">]</span># mkdir oracle
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/861ce9907f8b4d129fc446882b52ab11.png" alt="在这里插入图片描述"><br>
更改u01目录的所有者及所属组</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 u01<span class="token punctuation">]</span># chown <span class="token operator">-</span><span class="token constant">R</span> grid<span class="token operator">:</span>oinstall <span class="token operator">/</span>u01
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/0c448d17a3184175b84d4ac6305c0c9b.png" alt="在这里插入图片描述"><br>
进入u01目录查看子目录的权限，如下所示，我们需要将其中的oracle子目录的所有者改为oracle用户<br>
<img src="https://img-blog.csdnimg.cn/99f408f846da4bc583bbda3f4963cc12.png" alt="在这里插入图片描述"></p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 u01<span class="token punctuation">]</span># chown <span class="token operator">-</span><span class="token constant">R</span> oracle<span class="token operator">:</span>oinstall oracle
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/9552ce2be04f4ff99bcf88182c2a89b7.png" alt="在这里插入图片描述"><br>
改变u01目录的权限，因为后面安装软件需要往里面写文件，上面我们已经知道u01目录属于grid用户，其属组是oinstall，且u01目录的权限是755，所以grid用户有读写执行的权限，但是oracle用户只有读和执行的权限，这会导致安装数据库软件时没有权限将安装文件写入相应的目录，所以我们要改变u01目录的权限为775，让oinstall组对其有读写执行的权限，而oracle用户又属于oinstall组，此时oracle用户就拥有了对u01目录的读写执行权限.</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># chmod <span class="token number">775</span> u01
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/c232d8546f60415f830f48c0d4d5c67c.png" alt="在这里插入图片描述"></p>
<h3><a id="325_196"></a>3.2.5设置用户的环境变量</h3>
<p>设置grid用户的环境变量</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># su <span class="token operator">-</span> grid
<span class="token punctuation">[</span>grid@rac1 <span class="token operator">~</span><span class="token punctuation">]</span>$ vi <span class="token punctuation">.</span>bash_profile
在 <span class="token punctuation">.</span>bash_profile的行末加入以下变量
<span class="token constant">ORACLE_BASE</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>gridbase
<span class="token constant">ORACLE_HOME</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>grid

<span class="token constant">PATH</span><span class="token operator">=</span>$<span class="token constant">ORACLE_HOME</span><span class="token operator">/</span>bin<span class="token operator">:</span>$<span class="token constant">PATH</span>
<span class="token constant">LD_LIBRARY_PATH</span><span class="token operator">=</span>$<span class="token constant">ORACLE_HOME</span><span class="token operator">/</span>lib<span class="token operator">:</span>$<span class="token constant">LD_LIBRARY_PATH</span>

<span class="token constant">DISPLAY</span><span class="token operator">=</span><span class="token number">192.168</span><span class="token number">.88</span><span class="token number">.72</span><span class="token operator">:</span><span class="token number">0.0</span>

<span class="token keyword">export</span> <span class="token constant">ORACLE_BASE</span> <span class="token constant">ORACLE_HOME</span> <span class="token constant">PATH</span> <span class="token constant">LD_LIBRARY_PATH</span> <span class="token constant">DISPLAY</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/8ac0112fe5ec40bb8bc6b92ebec0e1db.png" alt="在这里插入图片描述"><br>
设置oracle用户的环境变量</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>grid@rac1 <span class="token operator">~</span><span class="token punctuation">]</span>$ vi <span class="token punctuation">.</span>bash_profile
<span class="token punctuation">[</span>grid@rac1 <span class="token operator">~</span><span class="token punctuation">]</span>$ su <span class="token operator">-</span> oracle
Password<span class="token operator">:</span> 
<span class="token punctuation">[</span>oracle@rac1 <span class="token operator">~</span><span class="token punctuation">]</span>$ vi <span class="token punctuation">.</span>bash_profile
在 <span class="token punctuation">.</span>bash_profile的行末加入以下变量
<span class="token constant">ORACLE_BASE</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>oracle
<span class="token constant">ORACLE_HOME</span><span class="token operator">=</span><span class="token operator">/</span>u01<span class="token operator">/</span>oracle<span class="token operator">/</span>db
<span class="token constant">ORACLE_SID</span><span class="token operator">=</span>racdb1
<span class="token constant">PATH</span><span class="token operator">=</span>$<span class="token constant">ORACLE_HOME</span><span class="token operator">/</span>bin<span class="token operator">:</span>$<span class="token constant">PATH</span>
<span class="token constant">LD_LIBRARY_PATH</span><span class="token operator">=</span>$<span class="token constant">ORACLE_HOME</span><span class="token operator">/</span>lib<span class="token operator">:</span>$<span class="token constant">LD_LIBRARY_PATH</span>

<span class="token constant">DISPLAY</span><span class="token operator">=</span><span class="token number">192.168</span><span class="token number">.88</span><span class="token number">.72</span><span class="token operator">:</span><span class="token number">0.0</span>

<span class="token keyword">export</span> <span class="token constant">ORACLE_BASE</span> <span class="token constant">ORACLE_HOME</span> <span class="token constant">ORACLE_SID</span> <span class="token constant">PATH</span> <span class="token constant">LD_LIBRARY_PATH</span> <span class="token constant">DISPLAY</span>

</code></pre>
<p><img src="https://img-blog.csdnimg.cn/b5ccb47b1525488aa9d66081d124e302.png" alt="在这里插入图片描述"><br>
安装一个小工具rlwrap，但是安装过程中出现一个小错误<br>
<img src="https://img-blog.csdnimg.cn/13de44e044e24703b2078140d94145c8.png" alt="在这里插入图片描述"><br>
根据错误提示要安装一个readline库，我用yum源安装就好了，安装好再次安装rlwrap即可</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 rlwrap<span class="token operator">-</span><span class="token number">0.37</span><span class="token punctuation">]</span># yum <span class="token operator">-</span>y install readline<span class="token operator">*</span>
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/894c1cbbb512471090687923861a2eea.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/202d6359c8cc4af5b36c402f1a096f39.png" alt="在这里插入图片描述"><br>
将rlwrap命令的命令的简写加入oracle用户和grid用户的环境变量中，到时可以直接在shell中输入命令运行<br>
<img src="https://img-blog.csdnimg.cn/8cca5bb378084a2db5e48ba660d47c61.png" alt="在这里插入图片描述"></p>
<h2><a id="33__242"></a>3.3 配置内核参数</h2>
<pre><code class="prism language-javascript">关闭防火墙
<span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># chkconfig iptables off
关闭selinux
<span class="token punctuation">[</span>root@rac1 selinux<span class="token punctuation">]</span># vi <span class="token operator">/</span>etc<span class="token operator">/</span>selinux<span class="token operator">/</span>config 
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/6bb62f4ad41a42a8b62f58a88547a0a6.png" alt="在这里插入图片描述"><br>
修改内核参数</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 selinux<span class="token punctuation">]</span># vi <span class="token operator">/</span>etc<span class="token operator">/</span>sysctl<span class="token punctuation">.</span>conf                 <span class="token comment">//进入该文件，添加下面的配置参数</span>
<span class="token punctuation">[</span>root@rac1 selinux<span class="token punctuation">]</span># sysctl <span class="token operator">-</span>p                           <span class="token comment">//修改后保存退出，运行此命令使修改生效</span>

fs<span class="token punctuation">.</span>aio<span class="token operator">-</span>max<span class="token operator">-</span>nr <span class="token operator">=</span> <span class="token number">1048576</span>
fs<span class="token punctuation">.</span>file<span class="token operator">-</span>max <span class="token operator">=</span> <span class="token number">6815744</span>
kernel<span class="token punctuation">.</span>shmall <span class="token operator">=</span> <span class="token number">4294967296</span>
kernel<span class="token punctuation">.</span>shmmax <span class="token operator">=</span> <span class="token number">68719476736</span>
kernel<span class="token punctuation">.</span>shmmni <span class="token operator">=</span> <span class="token number">4096</span>
kernel<span class="token punctuation">.</span>sem <span class="token operator">=</span> <span class="token number">250</span> <span class="token number">32000</span> <span class="token number">100</span> <span class="token number">128</span>
net<span class="token punctuation">.</span>ipv4<span class="token punctuation">.</span>ip_local_port_range <span class="token operator">=</span> <span class="token number">9000</span> <span class="token number">65500</span>
net<span class="token punctuation">.</span>core<span class="token punctuation">.</span>rmem_default <span class="token operator">=</span> <span class="token number">262144</span>
net<span class="token punctuation">.</span>core<span class="token punctuation">.</span>rmem_max <span class="token operator">=</span> <span class="token number">4194304</span>
net<span class="token punctuation">.</span>core<span class="token punctuation">.</span>wmem_default <span class="token operator">=</span> <span class="token number">262144</span>
net<span class="token punctuation">.</span>core<span class="token punctuation">.</span>wmem_max <span class="token operator">=</span> <span class="token number">1048576</span>

</code></pre>
<p>进入/etc/profile进行配置</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 selinux<span class="token punctuation">]</span># vi <span class="token operator">/</span>etc<span class="token operator">/</span>profile            <span class="token comment">//在行末加入下列代码，保存退出</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> $<span class="token constant">USER</span> <span class="token operator">=</span> <span class="token string">"oracle"</span> <span class="token punctuation">]</span> <span class="token operator">||</span> <span class="token punctuation">[</span>$<span class="token constant">USER</span> <span class="token operator">=</span> <span class="token string">"grid"</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> then
     <span class="token keyword">if</span> <span class="token punctuation">[</span> \$<span class="token constant">SHELL</span> <span class="token operator">=</span> <span class="token string">"/bin/ksh"</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> then
         ulimit <span class="token operator">-</span>p <span class="token number">16384</span>
         ulimit <span class="token operator">-</span>n <span class="token number">65536</span>
     <span class="token keyword">else</span> 
         ulimit <span class="token operator">-</span>u <span class="token number">16384</span> <span class="token operator">-</span>n <span class="token number">65536</span>
     fi
     umask <span class="token number">022</span>
fi

</code></pre>
<p>进入/etc/security/limits.conf进行配置</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># vi <span class="token operator">/</span>etc<span class="token operator">/</span>security<span class="token operator">/</span>limits<span class="token punctuation">.</span>conf          <span class="token comment">//在行末加入以下配置参数</span>
grid    soft    nproc   <span class="token number">2047</span>
grid    hard    nproc   <span class="token number">16384</span>
grid    soft    nofile  <span class="token number">1024</span>
grid    hard    nofile  <span class="token number">65536</span>
oracle  soft    nproc   <span class="token number">2047</span>
oracle  hard    nproc   <span class="token number">16384</span>
oracle  soft    nofile  <span class="token number">1024</span>
oracle  hard    nofile  <span class="token number">65536</span>


<span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># vi <span class="token operator">/</span>etc<span class="token operator">/</span>pam<span class="token punctuation">.</span>d<span class="token operator">/</span>login                    <span class="token comment">//在行末加入下面的语句</span>
session    required     pam_limits<span class="token punctuation">.</span>so
</code></pre>
<p>因为Oracle数据库的运行需要大内存，所以做以下操作，当然也可以不做，可以自行查一下</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># umount tmpfs
<span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># mount <span class="token operator">-</span>t tmpfs shmfs <span class="token operator">-</span>o size<span class="token operator">=</span><span class="token number">3000</span>m <span class="token operator">/</span>dev<span class="token operator">/</span>shm

<span class="token comment">//进一步进入/etc/fstab配置如下</span>
<span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># vi <span class="token operator">/</span>etc<span class="token operator">/</span>fstab
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/3a3dbdef9bc24fa29cd61ad39222e81f.png" alt="在这里插入图片描述"></p>
<h2><a id="34__309"></a>3.4 时间同步</h2>
<p>在此我们使用oracle rac的ctssd同步功能而不使用linux系统自带的ntpd同步功能<br>
首先，关闭ntpd服务</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># service ntpd stop    <span class="token comment">//关闭ntpd</span>
<span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># chkconfig ntpd off       <span class="token comment">//禁止ntpd开机自启</span>
</code></pre>
<p>将ntpd的配置文件隐藏，如下</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>root@rac1 <span class="token operator">/</span><span class="token punctuation">]</span># cd <span class="token operator">/</span>etc
<span class="token punctuation">[</span>root@rac1 etc<span class="token punctuation">]</span># ls ntp<span class="token operator">*</span>
ntp<span class="token punctuation">.</span>conf

ntp<span class="token operator">:</span>
crypto  keys  step<span class="token operator">-</span>tickers
<span class="token punctuation">[</span>root@rac1 etc<span class="token punctuation">]</span># mv ntp<span class="token punctuation">.</span>conf  ntp<span class="token punctuation">.</span>conf<span class="token punctuation">.</span>backup

<span class="token comment">//进入下面的文件看一下有无ntpd.pid，有的话删掉</span>
<span class="token punctuation">[</span>root@rac1 etc<span class="token punctuation">]</span># cd <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run
<span class="token punctuation">[</span>root@rac1 run<span class="token punctuation">]</span># ls <span class="token operator">-</span>l <span class="token operator">*</span><span class="token punctuation">.</span>pid
<span class="token punctuation">[</span>root@rac1 run<span class="token punctuation">]</span># rm <span class="token operator">-</span>f <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run<span class="token operator">/</span>ntpd<span class="token punctuation">.</span>pid

</code></pre>
<p><img src="https://img-blog.csdnimg.cn/a21ce2e858f04f9b87444fd49055ba04.png" alt="在这里插入图片描述"><br>
将上图中的ntpd.pid删除就可以了</p>
<p>配置rac1和rac2远程互信，这个可以在网上自行找教程，后面有时间再出教程</p>
<p>安装依赖包，我用的rpm命令安装的，这里不演示，缺少包的私聊找我要就可以了，我的安装过前的配置检查出现下面的问题，问题不大，照着改一下就可以了<br>
<img src="https://img-blog.csdnimg.cn/2657ec575e194455b44ab438e60787e3.png" alt="在这里插入图片描述"><img src="https://img-blog.csdnimg.cn/3a61f60515f648b4a522c106b45850db.png" alt="在这里插入图片描述"><br>
在安装缺少的包时，出现环形依赖，只要同时安装两个包就可以了，如下图所示<br>
<img src="https://img-blog.csdnimg.cn/4936fa75457e4d26883cdc9a3a3e94fa.png" alt="在这里插入图片描述"><br>
解决问题后再次检查环境配置就通过了<br>
<img src="https://img-blog.csdnimg.cn/ac899973a51b469fb5fc57cda00dfa6c.png" alt="在这里插入图片描述"><br>
就接下来，进入grid的安装<br>
<img src="https://img-blog.csdnimg.cn/46683497b3fc4ac690ded3563b71a006.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/0fa296e3ac534fb7b346e0d238a96007.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/0f98f201f3844c1db3309ce780834212.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/64c27cb5a2be451782514bd95857c5d5.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/8bb5082e1d6a4278a51cfbe867780429.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/bb715bf32cdb4b54a7c9dd19f03c765e.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/298fc29c3bcd4671ae99e24ed5b0e1b4.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/38943a1e88ab4e12a3f443de8f2ebdbe.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/aa0345323ade4a7aab0106e9dbf22c9b.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/f6321628da34436097940c4d34ba3269.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/f78a277072ae49d18765b6fb644845b3.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/3ee601d151014bf6ac71cc8b97f470dc.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/c6812adbf04d44129dd94f1052a6ca4d.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/9193ca44d0b946c8919a8e1e4614f770.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/b2b66a72f8104cca819bcb6e71083d53.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/b1bab9619c134e748101020d458c6ae2.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/598b2dad2206416e868d17bcf945c121.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/02f218a00cec4fb7bc617b5756350891.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/dea734fd3283466aaab4e1131d0167ce.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/4d898baad9344d598589364f16fa7e8c.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/ec8f45b43d6d4bb9b365882fbfca39fc.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/486ed42068a44d6fbd96dc5bfc18a06e.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/cb6b930fb6f148d3bca3eaa328d0ad4d.png" alt="在这里插入图片描述"><br>
<img src="https://img-blog.csdnimg.cn/ec87b5f309b746549e62ace64f48c5d7.png" alt="在这里插入图片描述"><br>
到此Oracle11gR2 rac安装结束.</p>
<h1><a id="4__371"></a>4 维护</h1>
<h2><a id="41__372"></a>4.1 集群维护</h2>
<p>CRS有一整套的工具集，它们都出现在$GRID_HOME/bin目录下，在 $ ORACLE_HOME中也有部分CRS工具可用，但Oracle推荐只使用$GRID_HOME/bin目录下的工具集。常用的有crsctl、crs_stat、diagcollection.pl、oifcfg等，下面介绍一些简单的应用。</p>
<h3><a id="411_CRS_374"></a>4.1.1 启动和停止CRS</h3>
<p>通常，RAC环境中的CRS都配置成了随机自动启动，但有时候需要调试CRS，或者OS需要维护，或者需要为GI软件打补丁时，需要手工启停CRS，手工启停CRS的命令很简单，与以前版本也是一致的，开启CRS：crsctl start crs，关闭CRS：crsctl stop crs，依旧需要特权用户root来完成CRS的启停。<br>
11g还引入了一个命令集来启停所有节点上运行的全部集群资源，包括数据库实例、ASM、VIP等等资源，非常方便：</p>
<pre><code class="prism language-javascript">Usage<span class="token operator">:</span>
  crsctl start cluster <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token operator">-</span>all<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token operator">-</span>n <span class="token operator">&lt;</span>server<span class="token operator">&gt;</span><span class="token punctuation">[</span><span class="token operator">...</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
    Start <span class="token constant">CRS</span> stack
where
    Default         Start local server
    <span class="token operator">-</span>all            Start all servers
    <span class="token operator">-</span>n              Start named servers
    server <span class="token punctuation">[</span><span class="token operator">...</span><span class="token punctuation">]</span>    One or more blank<span class="token operator">-</span>separated server names

<span class="token comment">//例如：停止所有节点上的css及资源：</span>
crsctl stop cluster <span class="token operator">-</span>all

<span class="token comment">//启动所有节点上的css及资源：</span>
crsctl start cluster <span class="token operator">-</span>all

</code></pre>
<h3><a id="412_CRS_394"></a>4.1.2 验证CRS</h3>
<p>面这些命令用来验证集群及其相关进程的状态（以grid、root用户执行皆可）。</p>
<pre><code class="prism language-javascript"><span class="token comment">//检查一个集群的当前运行状态：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl check cluster

<span class="token comment">//例如：</span>
<span class="token punctuation">[</span>root@node1 bin<span class="token punctuation">]</span># <span class="token punctuation">.</span><span class="token operator">/</span>crsctl check cluster
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4537</span><span class="token operator">:</span> Cluster Ready Services is online
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4529</span><span class="token operator">:</span> Cluster Synchronization Services is online
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4533</span><span class="token operator">:</span> Event Manager is online

<span class="token comment">//检查CRS的当前状态：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl check crs

<span class="token comment">//例如：</span>
<span class="token punctuation">[</span>grid@node1 <span class="token operator">~</span><span class="token punctuation">]</span>$ crsctl check crs
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4638</span><span class="token operator">:</span> Oracle High Availability Services is online
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4537</span><span class="token operator">:</span> Cluster Ready Services is online
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4529</span><span class="token operator">:</span> Cluster Synchronization Services is online
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4533</span><span class="token operator">:</span> Event Manager is online

<span class="token comment">//检查ohasd进程的状态：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl check has

<span class="token comment">//例如：</span>
<span class="token punctuation">[</span>grid@node1 <span class="token operator">~</span><span class="token punctuation">]</span>$ crsctl check has
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4638</span><span class="token operator">:</span> Oracle High Availability Services is online

<span class="token comment">//检查ctssd进程的状态：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl check ctss

<span class="token comment">//例如：</span>
<span class="token punctuation">[</span>grid@node1 <span class="token operator">~</span><span class="token punctuation">]</span>$ crsctl check ctss
<span class="token constant">CRS</span><span class="token operator">-</span><span class="token number">4700</span><span class="token operator">:</span> The Cluster Time Synchronization Service is <span class="token keyword">in</span> Observer mode<span class="token punctuation">.</span>
</code></pre>
<p><strong>备注</strong>：如果RAC时间的同步是采用第三方软件，比中ntp方式，那么ctss会处于observer状态</p>
<h3><a id="413_CRS_431"></a>4.1.3 禁用与启用CRS</h3>
<pre><code class="prism language-javascript"><span class="token comment">///若是不想让CRS随机启动，那么可以disable它：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl disable crs

<span class="token comment">///如果又改变了注意，可以enable：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl enable crs
</code></pre>
<h3><a id="414__439"></a>4.1.4 显示集群资源状态</h3>
<p>这个功能是11gR2中crsctl新具有的，</p>
<pre><code class="prism language-javascript">显示集群资源的状态：
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl stat res <span class="token operator">-</span>t

该命令与以前的crs_stat <span class="token operator">-</span>t基本类似

</code></pre>
<h3><a id="415_oifcfg_448"></a>4.1.5 使用oifcfg配置集群网络</h3>
<p>该命令包含了获取、删除与设置三部分，分别为oifcfg getif、oifcfg delif、oifcfg setif，更加具体的语法可以通过oifcfg -h来获取到<br>
例如：</p>
<pre><code class="prism language-javascript"><span class="token punctuation">[</span>grid@node1 <span class="token operator">~</span><span class="token punctuation">]</span>$ oifcfg getif
eth0  <span class="token number">192.168</span><span class="token number">.100</span><span class="token number">.0</span>  global  <span class="token keyword">public</span>
eth1  <span class="token number">10.10</span><span class="token number">.17</span><span class="token number">.0</span>  global  cluster_interconnect
</code></pre>
<p>4.1.6 使用diagcollection诊断集群<br>
该工具可以帮助DBA们一次性收集有关所有必需组件的诊断信息，如主机、操作系统、集群等等，这个工具位于$GRID_HOME/bin目录下，默认情况下，该工具将收集完整的诊断信息，但也可以使用正确的选项只收集想要的信息，如下命令只收集CRS的诊断信息：</p>
<pre><code class="prism language-javascript"><span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>grid<span class="token operator">/</span>product<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>bin<span class="token operator">/</span>diagcollection<span class="token punctuation">.</span>pl <span class="token operator">--</span>collect <span class="token operator">--</span>crs
</code></pre>
<h2><a id="42_OCR_461"></a>4.2 管理OCR</h2>
<p>OCR用来存储集群数据库的配置信息，对它的管理操作包括备份、恢复、添加、删除以及迁移等等</p>
<h3><a id="421__464"></a>4.2.1 备份</h3>
<p>OCR有自动备份，默认情况下，在集群运行的过程中，每4个小时就会对OCR进行一次备份，并保留最后的3个备份，每天和每周结束时，也会保留相应的一个备份。有几个命令被用来执行OCR备份相关的各种操作，比如查看OCR当前的一些信息并检查OCR是否损坏（用root用户执行）：</p>
<pre><code class="prism language-javascript"><span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrcheck
<span class="token comment">//例如：</span>
<span class="token punctuation">[</span>root@node1 bin<span class="token punctuation">]</span># <span class="token punctuation">.</span><span class="token operator">/</span>ocrcheck
Status <span class="token keyword">of</span> Oracle Cluster Registry is <span class="token keyword">as</span> follows <span class="token operator">:</span>
         Version                  <span class="token operator">:</span>          <span class="token number">3</span>
         Total <span class="token function">space</span> <span class="token punctuation">(</span>kbytes<span class="token punctuation">)</span>     <span class="token operator">:</span>     <span class="token number">262120</span>
         Used <span class="token function">space</span> <span class="token punctuation">(</span>kbytes<span class="token punctuation">)</span>      <span class="token operator">:</span>       <span class="token number">2792</span>
         Available <span class="token function">space</span> <span class="token punctuation">(</span>kbytes<span class="token punctuation">)</span> <span class="token operator">:</span>     <span class="token number">259328</span>
         <span class="token constant">ID</span>                       <span class="token operator">:</span>  <span class="token number">465396144</span>
         Device<span class="token operator">/</span>File Name         <span class="token operator">:</span>      <span class="token operator">+</span><span class="token constant">DATA</span>
                                    Device<span class="token operator">/</span>File integrity check succeeded

                                    Device<span class="token operator">/</span>File not configured

                                    Device<span class="token operator">/</span>File not configured

                                    Device<span class="token operator">/</span>File not configured

                                    Device<span class="token operator">/</span>File not configured

         Cluster registry integrity check succeeded
         Logical corruption check succeeded

<span class="token comment">//因为OCR的重要，备份OCR是项非常重要的工作，以下命令查看OCR的备份信息：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span>showbackup

<span class="token comment">//切换至root，使用如下命令可以用来手工备份OCR文件（root用户执行）：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span>manualbackup

<span class="token comment">//OCR的备份文件是一个二进制文件，但是可以使用ocrdump命令来查看它的内容（同样需要使用root用户）：</span>
cd <span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>
<span class="token punctuation">.</span><span class="token operator">/</span>ocrdump <span class="token operator">-</span>backupfile <span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>cdata<span class="token operator">/</span>racdb<span class="token operator">-</span>cluster<span class="token operator">/</span>backup00<span class="token punctuation">.</span>ocr

<span class="token comment">//为了让word中的显示不太混乱，先cd到了ocrdump命令所在的目录，这个命令会在命令执行的工作目录下生成一个名为OCRDUMPFILE的文本文件</span>
</code></pre>
<h3><a id="422__502"></a>4.2.2 恢复</h3>
<p>备份是为了在OCR损坏的关键时刻能够对其进行恢复，下面是一个简单的模拟恢复测试（使用root用户来执行下面这些命令）：</p>
<pre><code class="prism language-javascript"><span class="token comment">//在所有节点上执行如下命令来停止crs：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl stop crs

<span class="token comment">//如果OCR文件已经损坏，那么上述命令可能会报错，在命令中使用“-f”选项强制关停crs，然后在其中一个节点上将crs启动到独占模式：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl start crs <span class="token operator">-</span>excl

<span class="token comment">//使用ps命令来观察，如果crsd进程存在，使用如下命令先行关闭该进程：</span>
crsctl stop resource ora<span class="token punctuation">.</span>crsd <span class="token operator">-</span>init

<span class="token comment">//然后再使用ocrconfig命令查看备份文件所在的位置，并找合适的备份来恢复OCR：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span>restore <span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>cdata<span class="token operator">/</span>racdb<span class="token operator">-</span>cluster<span class="token operator">/</span>backup00<span class="token punctuation">.</span>ocr

<span class="token comment">//再度使用ocrcheck来检查OCR的状况，如正常，先将当前节点的crs关闭：</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl stop crs <span class="token operator">-</span>f

<span class="token comment">//crs可以正常启动了。</span>
</code></pre>
<h3><a id="423__522"></a>4.2.3 镜像维护</h3>
<p>当前的OCR所在的位置可以通过两个途径得到：一是ocrcheck命令，二是/etc/oracle/ocr.loc文件，既然OCR这么重要，如果使用前面的几个方法得知只有一份OCR的话，那么应该考虑为其创建镜像，OCR只能有一个镜像，也就是说OCR磁盘最多有两个，一个primary ocr，一个mirror ocr，以下操作都可以在crs运行时进行，依旧使用root用户来执行ocrconfig命令：</p>
<pre><code class="prism language-javascript"><span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span>add <span class="token operator">+</span><span class="token constant">ASM_TEST</span>
</code></pre>
<p>这里需要注意一点，在11.2版本具是用ASM来存放OCR，用来做OCR的diskgroup，也就是这里的+ASM_TEST，需要满足以下条件：</p>
<ul>
<li>1） 冗余配置为External时，至少需要300M；冗余配置为Normal的至少需要600M；冗余配置为High的至少需要900M；</li>
<li>2） 该磁盘必须在所有节点上挂载；</li>
<li>3） Compatible.asm参数必须设置至少为11.2（alter diskgroup +ASM_TEST set ATTRIBUTE ‘compatible.asm’=‘11.2’;）；</li>
<li>4） 所有节点上，GRID_HOME的权限为“6751”或“-rwsr-s—x”。<br>
下面的命令用来删除多余的OCR：</li>
</ul>
<pre><code class="prism language-javascript"><span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span><span class="token keyword">delete</span> <span class="token operator">+</span><span class="token constant">ASM_TEST</span>
</code></pre>
<h3><a id="424_OCR_536"></a>4.2.4 移动OCR</h3>
<p>有时在维护时可能会更改OCR的磁盘，也就是说将OCR从一个磁盘移动到另一个磁盘，那么也是可以的，只是在移动前必须先给OCR添加镜像OCR，然后再移动，步骤如下：<br>
当前的OCR是DATA，创建镜像DATA1，然后移动到DATA2</p>
<pre><code class="prism language-javascript">opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span>add <span class="token operator">+</span><span class="token constant">DATA1</span>
<span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrconfig <span class="token operator">-</span>replace <span class="token operator">+</span><span class="token constant">DATA</span> <span class="token operator">-</span>replacement <span class="token operator">+</span><span class="token constant">DATA2</span>
</code></pre>
<p>值得一提的是，ocrconfig还有-export和-import选项可以用来替代上面的备份与恢复过程。</p>
<h3><a id="425_OLR_545"></a>4.2.5 管理OLR</h3>
<p>OLR是11gR2引入的，它只存储与当前节点有关的配置信息，可以用ocrconfig命令来查看其信息：</p>
<pre><code class="prism language-javascript"><span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>ocrcheck <span class="token operator">-</span>local
</code></pre>
<p>很多管理ocr的ocrconfig命令可以在添加-local的选项下来对olr进行管理，如前面的-showbackup、-manualbackup等。</p>
<h2><a id="43_Voting_Disk_552"></a>4.3 管理Voting Disk</h2>
<p>从11gR2开始，无需对Voting Disk进行手工的备份，只要对集群的结构做了任何更改，Voting Disk会被自动备份到OCR中，如果添加了新的Voting Disk，那么Oracle会自动将以前备份的Voting Disk数据恢复到新添加的Voting Disk中。与OCR不同的是，Voting Disk的管理需要使用crsctl命令，下面的命令用来查询Voting Disk的有关信息：</p>
<pre><code class="prism language-javascript"><span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl query css votedisk

<span class="token comment">//例如：</span>
<span class="token punctuation">[</span>grid@node1 <span class="token operator">~</span><span class="token punctuation">]</span>$ crsctl query css votedisk
##  <span class="token constant">STATE</span>    File Universal Id                File Name Disk group
<span class="token operator">--</span>  <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>    <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>                <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span> <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>
 <span class="token number">1.</span> <span class="token constant">ONLINE</span>   <span class="token number">1</span><span class="token function">ed6e4e28dc94fb2bf991a1ff18b818f</span> <span class="token punctuation">(</span><span class="token constant">ORCL</span><span class="token operator">:</span><span class="token constant">DATAVG</span><span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token constant">DATA</span><span class="token punctuation">]</span>
Located <span class="token number">1</span> voting <span class="token function">disk</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">.</span>
</code></pre>
<p>当Voting Disk在ASM上的时候，不可以使用crsctl add/delete css votedisk命令，唯一可做的操作是可以将Voting Disk搬迁到其他的磁盘组上，不过这样的操作看来也没太多的用武之地，除非想要将其搬迁到冗余度更高的磁盘组上：</p>
<pre><code class="prism language-javascript"><span class="token operator">/</span>opt<span class="token operator">/</span><span class="token number">11.2</span><span class="token number">.0</span><span class="token operator">/</span>grid<span class="token operator">/</span>bin<span class="token operator">/</span>crsctl replace css votedisk <span class="token operator">+</span>asm_test
</code></pre>
<h2><a id="44_ASM_568"></a>4.4 ASM维护</h2>
<p>从11gR2开始，Oracle不再支持在dbca建库的时候选择裸设备，因此共享存储部分主要的选择就剩下了ASM，这里也只对ASM的管理进行简单的说明。<br>
在Oracle 11g RAC中，Oracle将ASM集成于GI软件中，现在的Voting Disk与OCR可以放置于ASM上了，这省去了为他们单独创建并管理一些裸设备的麻烦，在GI安装好后ASM实例就创建好并已经启来了，因为CRS要用到OCR和Voting Disk，如果ASM没有启来，CRS就无法读取它们的信息，当然ASM实例创建和ASM磁盘组管理都可以使用图形界面asmca来完成，因此下面这两部分主要以命令为主。</p>
<h3><a id="441_ASM_572"></a>4.4.1 ASM实例创建</h3>
<p>要想使用ASM，首要的工作就是创建ASM实例，既然是与数据库实例类似的实例，那么首先就需要有一个参数文件，只不过，ASM实例只需要关注少量的参数，与数据库的实例相比，比较特别的参数如下表所示：<br>
<img src="https://img-blog.csdnimg.cn/4a9aee0d91574fd792de0ad362ba41c9.png" alt="在这里插入图片描述"><br>
srvctl工具可以用来操作ASM实例，这与以往版本是一样的：srvctl status asm、srvctl start asm与srvctl stop asm，当然具体语法可以使用类似srvctl status asm –h来得到。</p>
<h3><a id="442__577"></a>4.4.2 磁盘组的创建与删除</h3>
<p>我们想要使用ASM，就必须先创建ASM DG（Disk Group），创建磁盘组的时候可以指定冗余策略，分别为：External外部冗余（依靠磁盘RAID），Normal为镜像冗余，而最高级的High则包含了总共三份冗余。创建DG的方法很简单，切换至grid用户，使用sqlplus命令来登录ASM实例：sqlplus ‘/as sysasm’，然后输入如下创建DG的语句：<br>
以grid用户sqlplus / as sysasm登录asm实例，然后执行语句：</p>
<pre><code class="prism language-javascript">create diskgroup data_bak external redundancy disk ‘<span class="token constant">ORCL</span><span class="token operator">:</span><span class="token constant">TESTVG</span>’<span class="token punctuation">,</span>‘<span class="token constant">ORCL</span><span class="token operator">:</span><span class="token constant">TESTVG2</span>’<span class="token punctuation">;</span>
</code></pre>
<p>很像创建表空间的语法，注意ASM DISK的书写，可以查询v$asm_disk.path字段来得到这些ASM DISK的正确路径。在create diskgroup语句完成后，DG将在当前操作的ASM实例中自动挂载，且添加到ASM实例的asm_diskgroups参数中。其他实例需要手工mount一下：</p>
<pre><code class="prism language-javascript">sqlplus <span class="token operator">/</span> sysasm
alter diskgroup data_bak mount<span class="token punctuation">;</span>
</code></pre>
<p>删除DG的语句更加简单：</p>
<pre><code class="prism language-javascript">drop diskgroup asm_test<span class="token punctuation">;</span>
</code></pre>
<p>前提是DG中没有任何内容，否则需要使用如下语句来删除：</p>
<pre><code class="prism language-javascript">drop diskgroup asm_test including contents<span class="token punctuation">;</span>
</code></pre>
<p>通过以下语句可以查看asm中是否存在该diskgroup:</p>
<pre><code class="prism language-javascript"><span class="token constant">SQL</span><span class="token operator">&gt;</span> select name <span class="token keyword">from</span> v$asm_diskgroup<span class="token punctuation">;</span>

<span class="token constant">NAME</span>
<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
<span class="token constant">DATA</span>
<span class="token constant">DATA_BAK</span>
</code></pre>
<h3><a id="443__605"></a>4.4.3 磁盘组的挂载与卸载</h3>
<p>DG只有在当前节点的ASM实例上挂载，才能被该节点的数据库实例访问：</p>
<pre><code class="prism language-javascript">alter diskgroup asm_test mount<span class="token punctuation">;</span>
</code></pre>
<p>想要dismount一个DG也很简单：</p>
<pre><code class="prism language-javascript">alter diskgroup asm_test dismount<span class="token punctuation">;</span>
</code></pre>
<p>如果该磁盘组正在被使用，那么可以在语句最后面添加force子句，强制卸载。<br>
可以通过以下语句来查询diskgroup的状态：</p>
<pre><code class="prism language-javascript"><span class="token constant">SQL</span><span class="token operator">&gt;</span>  select name<span class="token punctuation">,</span><span class="token constant">STATE</span> <span class="token keyword">from</span>  v$asm_diskgroup<span class="token punctuation">;</span>

<span class="token constant">NAME</span>                           <span class="token constant">STATE</span>
<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span> <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span>
<span class="token constant">DATA</span>                           <span class="token constant">MOUNTED</span>
<span class="token constant">DATA_BAK</span>                       <span class="token constant">MOUNTED</span>
</code></pre>
<h3><a id="444__624"></a>4.4.4 磁盘的添加与删除</h3>
<p>从DG中删除磁盘的操作：</p>
<pre><code class="prism language-javascript"><span class="token constant">ALTER</span> <span class="token constant">DISKGROUP</span> dgroupA drop <span class="token constant">DISK</span> '<span class="token operator">/</span>devices<span class="token operator">/</span>Disk1’<span class="token punctuation">;</span>
</code></pre>
<p>添加磁盘：</p>
<pre><code class="prism language-javascript"><span class="token constant">ALTER</span> <span class="token constant">DISKGROUP</span> dgroupA <span class="token constant">ADD</span> <span class="token constant">DISK</span> <span class="token string">'/devices/D*'</span><span class="token punctuation">;</span>
</code></pre>
<p>无论是添加磁盘还是删除磁盘，都会触发磁盘组的重平衡，为了减少重平衡的影响，应将删除或者添加磁盘操作一次性完成。还有值得一提的是：在删除磁盘的时候因为需要将删除磁盘上的内容重平衡至其他磁盘，因此删除操作要比较长的时间，在期间可以用如下命令取消删除磁盘的操作：</p>
<pre><code class="prism language-javascript">alter diskgroup asm_test undrop disks<span class="token punctuation">;</span>
</code></pre>
<p>但如果删除时加上了force关键字，那么这个删除操作就不可逆了。<br>
可以通过以下语句来查看某磁盘是否还存在，以及它们的状态：</p>
<pre><code class="prism language-javascript"><span class="token constant">SQL</span><span class="token operator">&gt;</span>  select <span class="token constant">GROUP_NUMBER</span><span class="token punctuation">,</span><span class="token constant">DISK_NUMBER</span><span class="token punctuation">,</span><span class="token constant">MOUNT_STATUS</span><span class="token punctuation">,</span><span class="token constant">NAME</span><span class="token punctuation">,</span><span class="token constant">PATH</span> <span class="token keyword">from</span> v$asm_disk<span class="token punctuation">;</span>

<span class="token constant">GROUP_NUMBER</span> <span class="token constant">DISK_NUMBER</span> <span class="token constant">MOUNT_S</span> <span class="token constant">NAME</span>                 <span class="token constant">PATH</span>
<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span> <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span> <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span> <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span> <span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span>
           <span class="token number">1</span>           <span class="token number">0</span> <span class="token constant">CACHED</span>  <span class="token constant">DATAVG</span>               <span class="token constant">ORCL</span><span class="token operator">:</span><span class="token constant">DATAVG</span>
           <span class="token number">2</span>           <span class="token number">0</span> <span class="token constant">CACHED</span>  <span class="token constant">TESTVG</span>               <span class="token constant">ORCL</span><span class="token operator">:</span><span class="token constant">TESTVG</span>
</code></pre>
<h3><a id="445__647"></a>4.4.5 磁盘组信息的查询</h3>
<p>比较常用的几个V视图：vasm_diskgroup、vasmdisk 、 v asm_disk、vasm9disk、vasm_client，<br>
还有两个查询性能统计信息的视图：9vasmdiskstat 、 vasm_disk_stat、vasm 9diskstat、vasm_diskgroup_stat。</p>
<h3><a id="446__651"></a>4.4.6 磁盘组的重平衡</h3>
<p>除了通过ASM的初始化参数asm_power_limit参数来调节重平衡外，也可以使用如下语句来触发重平衡：<br>
alter diskgroup asm_test rebalance power 11 wait;<br>
其中power子句后的数字指定了重平衡的力度，与参数一样，取值范围0～11，但如果这里的值大于asm_power_limit参数，那么这里的指定不起任何作用；最后面的wait子句代表这个命令等待重平衡结束后再返回，如果没有wait，那么该命令立刻返回，当然重平衡操作会在后台继续。</p>
<h3><a id="447_ASM_656"></a>4.4.7 ASM工具</h3>
<p>下面两个工具，asmcmd在10g就出现了，asmca是11g才新加入ASM家族的实用工具。</p>
<ul>
<li>asmca<br>
asmca是从11g引入一个图形工具，它的使用在前面安装部分已经有较为详细的描述，它可以用来进行ASM相关的绝大部分管理操作，非常方便，有一点需要注意：从11g开始，dbca不再支持创建和配置ASM磁盘组，打开dbca界面后不要傻眼就是。</li>
<li>asmcmd<br>
10gR2的时候，asmcmd包含了一些UNIX风格的命令，比如ls、du、cd等等，但当时这些命令基本上还处于中看不中用的状态，11g后，Oracle加入了非常多的新命令，甚至可以在asmcmd下来管理ASM实例和磁盘组，可以完成前面ASM磁盘组管理中介绍的所有管理操作！asmcmd又提供了非常详尽的命令帮助页，在以后的工作中可以慢慢去体会。</li>
</ul>
<h2><a id="45__663"></a>4.5 数据库维护</h2>
<h3><a id="451__664"></a>4.5.1 参数维护</h3>
<p>在RAC环境中，Oracle建议使用共享的spfile，在默认的安装下就是如此，而在每个节点oracle用户的$ORACLE_HOME/dbs目录下有一个pfile：init ${ORACLE_SID}.ora，里面有一行参数指定了spfile的所在，比如：<br>
SPFILE=’+ASM_DATA/racdb/spfileracdb.ora’<br>
在这个二进制spfile中，包含了数据库的非默认初始化参数，参数的格式为：<br>
&lt;instance_name&gt;.&lt;parameter_name&gt;=&lt;parameter_value&gt;<br>
如果在instance_name部分使用了“*”或者没有取值，那么意味着这个参数对于所有的实例都是有效的。</p>
<p>与单实例数据库一样，还是可以使用alter system set … 命令来修改参数的值，但是语法却有所不同，这个命令的完整语法为：<br>
alter system set &lt;parameter_name&gt; = &lt;parameter_value&gt; scope = &lt;memory|spfile|both&gt; comment = &lt;’comments’&gt; deferred sid = &lt;sid|*&gt;<br>
其中：</p>
<p>Scope=memory 表明这些改变会在实例重启后丢失，如果某参数只能针对本地实例进行修改，那么这个选项就将使命令报错；<br>
Scope=spfile 表明只在spfile中进行参数的修改，实例重启后生效，如果实例不是使用spfile，而是pfile启动的，那么这个选项也会使得命令报错；<br>
Scope=both 表明所做的参数改动在当前环境有效，且在实例启动后依然有效；<br>
Comment 没什么好说的，注释而已；<br>
Deferred 表明所做的参数修改仅对发出该命令后生成的会话有效；<br>
Sid 使用sid子句允许指定实例名称，使得指定的实例受参数修改的影响，如果使用“*”，那么就针对所有实例进行修改，这是默认取值。</p>
<h3><a id="452__682"></a>4.5.2 启动和停止实例</h3>
<p>Srvctl工具非常强大，在后面将介绍其更多的功能，其中一个简单的应用就是启停RAC数据库。我们可以使用下面两条简单的命令分别来启动、关闭数据库：</p>
<pre><code class="prism language-javascript">srvctl start database <span class="token operator">-</span>d racdb
srvctl stop database <span class="token operator">-</span>d racdb <span class="token operator">-</span>o immediate
</code></pre>
<p>这两条命令将对RAC数据库中的所有实例生效，其中stop database时的immediate，与sqlplus中shutdown命令的immediate含义一样，且srvctl命令也支持其他几个诸如normal、transactional、abort等参数，下面的stop instance命令中-o选项所跟的参数也是一样的道理——与10g的时候一样，也可以使用srvctl命令来启停RAC中的单个实例：</p>
<pre><code class="prism language-javascript">srvctl start instance <span class="token operator">-</span>d racdb <span class="token operator">-</span>n racdb1
srvctl stop instance <span class="token operator">-</span>d racdb <span class="token operator">-</span>n racdb1 <span class="token operator">-</span>o immedaite
</code></pre>
<p>单实例数据库一样，也可以使用sqlplus中的starup与shutdown命令来启停数据库，确切地讲，是启停当前登录的实例，它们的用法与单实例数据库是相同的。</p>
<h3><a id="453_UNDO_695"></a>4.5.3 管理UNDO</h3>
<p>在RAC数据库中，表空间的管理基本与单实例数据库是一样的，也有但有一个例外：UNDO表空间，在RAC中，每个实例都需要一个自己的UNDO表空间，可以查看初始化参数UNDO_TABLESPACE来了解当前实例所使用的UNDO表空间。<br>
说到UNDO，还是提下单实例数据库中就存在的一个管理操作，就是替换实例的当前UNDO表空间，先创建一个UNDO表空间：</p>
<pre><code class="prism language-javascript">create undo tablespace undo_test datafile size <span class="token number">10</span>m<span class="token punctuation">;</span>
</code></pre>
<p>再来使用参数切换UNDO表空间：</p>
<pre><code class="prism language-javascript">alter system <span class="token keyword">set</span> undo_tablespace<span class="token operator">=</span><span class="token string">'UNDO_TEST'</span><span class="token punctuation">;</span>
</code></pre>
<p>测试了下这个参数的更改有点特别，不能指定sid，且只在当前实例生效。</p>
<h3><a id="454_redo_log_707"></a>4.5.4 管理redo log</h3>
<p>与单实例数据库不同的是，RAC数据库中，每个实例都有自己的online redo log，自然也有单独的log buffer、单独的归档日志文件。每个数据库实例的redo log称为一个线程，这在v$log、v $archived_log等重要视图中都可得到。</p>
<h3><a id="455__710"></a>4.5.5 在线日志</h3>
<p>日常做的最多的与online redo log相关的管理操作就是添加删除日志了，其实大多时候还是与单实例是一样的，简单的使用如下命令就为当前实例添加一组在线日志：</p>
<pre><code class="prism language-javascript">alter database add logfile group <span class="token number">5</span> size <span class="token number">10</span>m<span class="token punctuation">;</span>
</code></pre>
<p>如果想为其他的实例添加日志文件，那么就需要制定实例名：</p>
<pre><code class="prism language-javascript">alter database add logfile instance <span class="token string">'racdb2'</span> group <span class="token number">6</span> size <span class="token number">10</span>m<span class="token punctuation">;</span>
</code></pre>
<p>或者</p>
<pre><code class="prism language-javascript">alter database add logfile thread <span class="token number">1</span> group <span class="token number">6</span> size <span class="token number">10</span>m<span class="token punctuation">;</span>
</code></pre>
<p>而删除与单实例相同，只要指定group#即可，无需指定实例名。</p>
<h3><a id="456__725"></a>4.5.6 归档日志</h3>
<p>修改RAC数据库为归档模式或者关闭归档模式的方法也很简单：关闭所有实例，将其中一个实例打开到mount状态，执行如下语句：</p>
<pre><code class="prism language-javascript">alter database archivelog<span class="token punctuation">;</span>
</code></pre>
<p>语句是与单实例时代是一样的，之后打开所有实例即可。<br>
归档日志的存放可以各实例分离，但是要注意的是，数据库的备份与恢复是在一个实例完成的，因此必须实现归档在各个实例间的共享问题，online redo log也一样，平常正常工作时各个实例对自己的online redo log进行写入，但是在实例恢复时，可能需要读取其他实例的online redo log，因此也需要实现共享。<br>
值得一提的单实例不同的切换日志的命令在RAC中也与单实例有所不同，alter system switch logfile; 命令只能在当前实例进行日志切换，想要在所有实例进行日志切换就需要变通地执行命令：</p>
<pre><code class="prism language-javascript">alter system archive log current<span class="token punctuation">;</span> 
</code></pre>
<p>当然单实例数据库也有这个命令。使用这个命令还可以对指定实例进行日志切换：</p>
<pre><code class="prism language-javascript">alter system archive log instance <span class="token string">'racdb2'</span> current<span class="token punctuation">;</span>
</code></pre>
<p>最后提一下与日志相关的发出检查点操作的命令，在RAC数据库中也有所不同，以前的alter system checkpoint与alter system checkpoint global; 命令是等价的，将在所有数据库实例中触发检查点操作，若是想要在当前实例触发检查点，那么需要对命令稍作修改：</p>
<pre><code class="prism language-javascript">alter system checkpoint local<span class="token punctuation">;</span>
</code></pre>
<h3><a id="457__744"></a>4.5.7 管理服务</h3>
<p>服务用来在Oracle RAC环境中来管理工作量，它提供了一种对工作量进行分组的逻辑方法，将采用相同数据集、相同功能以及相同服务级需求的用户分组在一起，因此服务也经常被用来将不同的用户分组的连接“引导”到不同的RAC实例上，从而减少RAC数据库环境中集群方面的相关等待。<br>
早期的版本中可以使用dbca来管理服务，那也是最方便快捷的添加服务的方法，但是在11gR2中，dbca关于服务的这个选项已经被去除了，还可以通过em来进行配置，但Oracle推荐使用上面介绍的srvctl命令来对服务进行管理。<br>
用oracle用户登录，使用如下命令来为racdb数据库创建一个服务ssfxdw，将racdb1定义为首选实例，将racdb2定义为次选实例，且创建basic TAF策略，将服务配置为自动启动：</p>
<pre><code class="prism language-javascript">srvctl add service <span class="token operator">-</span>d racdb <span class="token operator">-</span>s ssfxdw <span class="token operator">-</span><span class="token constant">P</span> <span class="token constant">BASIC</span> <span class="token operator">-</span>y <span class="token constant">AUTOMATIC</span> <span class="token operator">-</span>r racdb1 <span class="token operator">-</span>a racdb2
</code></pre>
<p>动上面创建的服务：</p>
<pre><code class="prism language-javascript">srvctl start service <span class="token operator">-</span>d racdb <span class="token operator">-</span>s ssfxdw
</code></pre>
<p>关闭服务：</p>
<pre><code class="prism language-javascript">srvctl stop service <span class="token operator">-</span>d racdb <span class="token operator">-</span>s ssfxdw
</code></pre>
<h3><a id="458__759"></a>4.5.8 备份与恢复</h3>
<ul>
<li>备份
<ul>
<li>1） 操作系统的冷备：在关闭数据库的情况下，在文件级别对数据库的数据文件、控制文件、归档日志、在线日志、参数文件。</li>
<li>2） 使用rman工具对数据库备份和恢复，这里主要要了解全库备份、两种增量备份方式（差异增量备份和累积增量备份）</li>
</ul>
</li>
<li>恢复
<ul>
<li>1） 不完全恢复</li>
<li>2） 完全恢复<br>
Oracle RAC的备份与恢复与单实例数据库其实相差不大，有几点需要注意：<br>
RAC数据库的实例恢复与崩溃恢复是不一样的概念，虽然两者都只需要读取online redo log，但是实例恢复是指正常实例利用异常终止实例的online redo log，对该实例中被修改但未写入数据文件的数据块进行恢复，所以，RAC数据库的哦你online redo log必须共享；而崩溃恢复是指RAC数据库中的所有实例都出现故障，需要使用online redo log进行恢复；</li>
</ul>
</li>
</ul>
<p>RAC数据库的介质恢复与单实例基本相同，但是在RAC数据库恢复过程中，需要读取所有实例的归档日志，所以它们的归档日志也必须是共享的。<br>
查看附录中备份与恢复的实例进一步地了解。</p>
<h3><a id="459__773"></a>4.5.9 查看监听</h3>
<pre><code class="prism language-javascript"><span class="token comment">//查看监听状态：</span>
lsnrctl status

<span class="token comment">//启动监听：</span>
lsnrctl start

<span class="token comment">//关闭监听：</span>
lsnrctl stop
</code></pre>
<h2><a id="46__785"></a>4.6 告警日志查看</h2>
<p>一般系统出现问题，在我们查看过操作系的CPU、内存、磁盘IO后，往往只了解这些信息是不够的，我们还得从集群软件、ASM、数据库层去查找问题的所在，首先肯定要查看的各个层面的告警日志，那么这日志文件是放在哪里的呢？</p>
<ul>
<li>集群软件日志<br>
Oracle的集群软件Clusterware不像数据库有很多的视图或者工具来帮助诊断，它的日志和trace文件是唯一的选择，它主要的日志文件目录结构如下：<br>
日志的根目录CRS的安装目录，也就是grid用户的 $ ORACLE_HOME（在10g中会设置成$ CRS_HOME）/log/[node]，其中node是节点的名称。<br>
alertnode1.log：其中node1是结点的名称，这个日志相当于数据库的alert.log，一般应该作为检查的起点；<br>
crsd、cssd、evmd：分别是3个目录，分别对应着Clusterware三个同名的进程的日志，日志的名字和进程名字一致，分别叫crsd.log、ocssd.log、evmd.log；<br>
racg：这个目录里放置的是所有nodeapp的日志，包括ONS、VIP，每个日志从名字上就很容易辨别所对的nodeapp；<br>
client：这个目录里放置的是工具执行日志，比如ocrcheck、ocrconfig等，这些工具运行时产生的日志就会放在这个目录下。</li>
<li>ASM日志<br>
这里只需要掌握一下ASM的告警日志存放路径就行了，如果ASM实例启不来，我们就可以去查看一下这个日志文件，它在grid用户的$ORACLE_BASE/diag/asm/+ASM/+ASM1/trace目录下，以.log结尾的那个文件就是了，其中+ASM1是ASM实例的名称，一般情况下，第一个节点就是+ASM1，第二个节点就是+ASM2，以此类推。例如：</li>
</ul>
<pre><code class="prism language-javascript"><span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>oracle<span class="token operator">/</span>diag<span class="token operator">/</span>asm<span class="token operator">/</span><span class="token operator">+</span>asm<span class="token operator">/</span><span class="token operator">+</span><span class="token constant">ASM1</span><span class="token operator">/</span>trace<span class="token operator">/</span>alert_<span class="token operator">+</span><span class="token constant">ASM1</span><span class="token punctuation">.</span>log
</code></pre>
<ul>
<li>数据库日志<br>
数据库的告警日志文件存放的路径默认是在oracle用户的$ORACLE_BASE/diag/rdbms/数据库名/实例名/trace目录下，以.log结尾的文件就是了，例如：</li>
</ul>
<pre><code class="prism language-javascript"><span class="token operator">/</span>oracle<span class="token operator">/</span>app<span class="token operator">/</span>oracle<span class="token operator">/</span>diag<span class="token operator">/</span>rdbms<span class="token operator">/</span>orcl<span class="token operator">/</span>orcl1<span class="token operator">/</span>trace<span class="token operator">/</span>alert_orcl1<span class="token punctuation">.</span>log
</code></pre>
<ul>
<li>监听日志<br>
监听日志文件是$ORACLE_BASE/diag/tnslsnr/node1/listener/alert/log.xml，其中node1是节点名，也可以从lsnrctl status中Listener Log File后面内容看出来。</li>
</ul>
</div>
</body>

</html>
